package com.sj.common.resultVo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo<T> {
    private Integer code;
    private String msg;
    private T data;

    public static ResultVo success(Integer i) {
        return null;
    }
    public static ResultVo fail(String msg) {
        ResultVo<Object> rv = new ResultVo<>();
        rv.setMsg(msg);
        rv.setCode(-1);
        return rv;
    }
    public ResultVo(int code, String mesage) {
        setCode(code);
        setMsg(mesage);
    }

    public ResultVo(IErrorCode errorCode, T data) {
        setCodeMessage(errorCode);
        setData(data);
    }

    public ResultVo setCodeMessage(IErrorCode codeMessage) {
        setCode(codeMessage.getCode());
        setMsg(codeMessage.getMsg());
        return this;
    }
}
